
package com.hyfrogx.modules.manage.controller;
import com.hyfrogx.common.param.ErrorCode;
import com.hyfrogx.common.param.JSONResult;
import com.hyfrogx.common.param.LiResult;
import com.hyfrogx.modules.app.entity.User;
import com.hyfrogx.modules.app.utils.FrogConstant;
import lombok.extern.log4j.Log4j;
import org.apache.shiro.SecurityUtils;

@Log4j
public class BaseController
{
    /**
     * 从Shrio里获取登陆用户
     * @return
     */
    public User getLoginUser()
    {
        Object pricipal = SecurityUtils.getSubject().getPrincipal();
        if(null != pricipal){
            return (User)pricipal;
        }
        return null;
    }

    /**
     * c成功
     */
    final public JSONResult ajaxSuccess()
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.Success);
        ecologyResp.setMsg("success");
        return ecologyResp;
    }

    final public JSONResult ajaxSuccess(String msg)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.Success);
        ecologyResp.setMsg(msg);
        return ecologyResp;
    }

    final public JSONResult ajaxSuccessTest(String result)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.Success);
        ecologyResp.setResult(result);
        return ecologyResp;
    }

    final public JSONResult ajaxSuccess(Object data)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.Success);
        ecologyResp.setResult(data);
        return ecologyResp;
    }

    final public LiResult ajaxLiSuccess(Object data)
    {
        LiResult ecologyResp = new LiResult();
        ecologyResp.setError(FrogConstant.CommonStatus.ERROR);
        ecologyResp.setUrl(data.toString());
        return ecologyResp;
    }

    final public LiResult ajaxLiFail(String message)
    {
		LiResult ecologyResp = new LiResult();
	    ecologyResp.setError(FrogConstant.CommonStatus.NORMAL);
	    ecologyResp.setMessage(message);
        return ecologyResp;
    }

    /**
     * 失败
     */
    final public JSONResult ajaxFail(ErrorCode errorCode)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(errorCode);
        return ecologyResp;
    }

    final public JSONResult ajaxFail(String message)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.CODE);
        ecologyResp.setMsg(message);
        return ecologyResp;
    }

    final public JSONResult ajaxOtherFail(String message)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(ErrorCode.VERSION_TOO_LOW);
        ecologyResp.setMsg(message);
        return ecologyResp;
    }


    final public JSONResult ajaxFail(ErrorCode errorCode , String message)
    {
        JSONResult ecologyResp = new JSONResult();
        ecologyResp.setCode(errorCode);
        ecologyResp.setMsg(message);
        return ecologyResp;
    }
}
